package com.example.jpa.controller;

import com.example.jpa.entity.User;
import com.example.jpa.service.impl.UserService;
import com.example.jpa.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("login")
    public Object login(@RequestParam String username, String password){
        User user=userService.login(username,password);
        return ResultVo.builder().code(200).message("success").data(user).build();
    }

    @PostMapping("like")
    public Object login(@RequestParam String username){
        List<User> list=userService.like(username);
        return ResultVo.builder().code(200).message("success").data(list).build();
    }

    @PostMapping("list")
    public Object list(User user){
        List<User> list=userService.list(user);
        return ResultVo.builder().code(200).message("success").data(list).build();
    }

    @PostMapping("page")
    //pageNum默认从0开始
    public Object page(User user,int pageSize,int pageNum){
        Page<User> page = userService.page(user, pageSize, pageNum - 1);
        return ResultVo.builder().code(200).message("success").data(page).build();
    }


}
